<!DOCTYPE html>
<html lang="zh">
  
  <head>
    <meta charset="utf-8">
    <link rel="shortcut icon" href="img/favicon.png">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <link href="css/bootstrap-reset.css" rel="stylesheet">
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.validate.min.js"></script>
    <script type="text/javascript" src="js/form-validation-script.js"></script>
    <script type="text/javascript" src="js/jquery.validate.min.msg.js"></script>
    <script type="text/javascript" src="js/myjs/util.js"></script>
    <script type="text/javascript" src="js/myjs/validate.js"></script>
    <script type="text/javascript">
	    $(document).ready(function() {
			init();
		});
	    function init(){
	    	changeCardNo();
	    	bind();
	    }
	    function changeCardNo(){
	    	var re = $('input[name="cardType"]:checked').val();
	    	re="0"+re;
	    	$("#cardNo").val(formatDate(new Date(),"2")+re);
	    }
	    function changeType(){
	    	var re = $('input[name="cardType"]:checked').val();
	    	if("1"==re){
		    	$("#leftTimesDiv").css("display","none");
		    	$("#discountRateDiv").css("display","block");
	    	}
	    	if("2"==re){
		    	$("#leftTimesDiv").css("display","block");
		    	$("#discountRateDiv").css("display","none");
	    	}
	    	$("#discountRateDiv").css("","");
	    }
	    function bind(){
	    	$("input[name='cardType']").bind("change",function(){
	    		changeCardNo();
		    	changeType();
    		});
	    }
    	
					
		function addMemberCard() {
			var url = "/yuea/weixin/membershipCard/addMemberShipCard";
			var data = {};
			data.cardType = $('input[name="cardType"]:checked').val();
			data.cardNo = $("#cardNo").val();
			data.customerName = $("#customerName").val();
			data.userId = $("#userId").val();
			data.telphoneNo = $("#telphoneNo").val();
			data.accountBalance = $("#accountBalance").val();
			data.discountRate = $("#discountRate").val();
			data.leftTimes = $("#leftTimes").val();
			data.comment = $("#comment").val();
			var couponsStr = "";
			$.ajax({
			url : url,
			type : "post",
			contentType : "application/json",
			dataType : "json",
			data : JSON.stringify(data),
			success : function(response) {
				if (response.state == "BUSI_STATE_OK") {
					returnList();
				}
				returnList();
			},
			error : function(response) {
				alert(JSON.stringify(data));
			}
		})
	}
		
	function returnList(){
		window.location.href="memberCard.html";
	}
  </script>
  </head>
  
  <body>
    <section id="container" class="">
      <section id="main-content">
        <section class="wrapper">
          <!-- page start-->
          <div class="row">
            <div class="col-lg-12">
              <section class="panel">
                <header class="panel-heading">添加会员卡</header>
                <div class="panel-body">
					<div class="btn-group">
	                     <button id="editable-sample_new" class="btn btn-success" onclick="returnList()">
	                         	返回会员管理列表 <i class="fa fa-mail-reply (alias)"></i>
	                     </button>
	                 </div>
                  <div class=" form">
                    <form class="cmxform form-horizontal tasi-form" id="commentForm" method="get" action="">
                      <div class="form-group">
                        <label class="col-sm-2 control-label col-lg-2" for="inputSuccess">会员卡类型 <span style="color: red"> *</span></label>
                        <div class="col-lg-10">
                          <div class="radio">
                            <label>
                              <input type="radio" name="cardType" id="optionsRadios1" value="1" checked>充值折扣卡</label>
                            <label>
                              <input type="radio" name="cardType" id="optionsRadios2" value="2">计次卡</label></div>
                        </div>
                      </div>
                      <div class="form-group ">
                        <label for="cname" class="control-label col-lg-2">会员卡号
                          <span style="color: red"> *</span></label>
                        <div class="col-lg-10">
                          <input class="form-control" id="cardNo" name="cardNo" maxlength ="10" minlength="10" type="text"  required /></div>
                      </div>
                    <div class="form-group">
	                       <label class="col-sm-2 control-label col-lg-2" for="inputSuccess">客户姓名<span style="color: red"> *</span></label>
	                       <div class="col-lg-10">
	                           <div class="input-group m-bot15">
	                               <span class="input-group-btn">
	                                 <button type="button" class="btn btn-white"><i class="fa fa-search-plus"></i></button>
	                               </span>
	                               <input  id="customerName" name="customerName" type="text" maxlength ="16" minlength="2" class="form-control" placeholder="若已关注微信，可点击放大镜查找">
	                               <input  id="userId" name="userId" type="text" class="form-control" style="display: none" placeholder="若已关注微信，可点击放大镜查找">
	                           </div>
	
	                		</div>
	                 </div>
                      <div class="form-group ">
                        <label for="cemail" class="control-label col-lg-2">手机号<span style="color: red"> *</span></label>
                        <div class="col-lg-10">
                          <input class="form-control " id="telphoneNo" name="telphoneNo" maxlength ="11" type="number" minlength="11" placeholder="请输入11位手机号" required /></div>
                      </div>
                      <div class="form-group ">
                        <label for="cemail" class="control-label col-lg-2">充值金额<span style="color: red"> *</span></label>
                        <div class="col-lg-10">
	                      <input id="accountBalance" name="accountBalance"  class="form-control" type="number" min=1 placeholder="最低充值1元" required/>
                          </div>
                      </div>
                      <div  id="discountRateDiv" class="form-group">
                        <label for="curl" class="control-label col-lg-2">折扣<span style="color: red"> *</span></label>
                        <div class="col-lg-10">
                          <input class="form-control " id="discountRate" name="discountRate" type="number" min="0.01" max=0.99 placeholder="请输入0.01到0.99之间的数字" required/></div>
                      </div>
                      <div id="leftTimesDiv" class="form-group" style="display: none">
                        <label for="curl" class="control-label col-lg-2">剩余次数<span style="color: red"> *</span></label>
                        <div class="col-lg-10">
                          <input class="form-control " id="leftTimes" name="leftTimes" type="number" placeholder="" required/></div>
                      </div>
                      
                      <div class="form-group ">
                        <label for="ccomment" class="control-label col-lg-2">备注</label>
                        <div class="col-lg-10">
                          <textarea class="form-control " id="comment" name="comment" maxlength ="128"  placeholder="最多128个字符"></textarea>
                        </div>
                      </div>
                      <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-10">
                          <button class="btn btn-success" type="button" onclick="addMemberCard()">保存</button>
                          <button class="btn btn-default" type="returnList()">取消</button></div>
                      </div>
                    </form>
                  </div>
                </div>
              </section>
            </div>
          </div>
          <!-- page end--></section>
      </section>
      <!--main content end--></section>
  </body>

</html>